import { ApiProperty } from '@nestjs/swagger';
import { Column, Entity, ManyToOne, JoinColumn } from 'typeorm';
import { BaseEntity } from '../../../base.entity';
import WipBadRegistration from './wip-bad-registration.entity';

@Entity({ name: 'wip_bad_registration_list' })
export default class WipBadRegistrationList extends BaseEntity {
  @Column({
    type: 'varchar',
    length: 50,
    name: 'bad_registration_code',
    comment: '不良登记编号',
  })
  @ApiProperty()
  badRegistrationCode: string;

  @Column({
    type: 'varchar',
    length: 50,
    name: 'bad_code',
    comment: '不良现象编码',
    nullable: true,
  })
  @ApiProperty()
  badCode: string;

  @Column({
    type: 'varchar',
    length: 100,
    name: 'bad_name',
    comment: '不良现象名称',
    nullable: true,
  })
  @ApiProperty()
  badName: string;

  @Column({
    type: 'varchar',
    length: 100,
    name: 'bad_level_code',
    comment: '缺陷等级编码',
    nullable: true,
  })
  @ApiProperty()
  badLevelCode: string;

  @Column({
    type: 'varchar',
    length: 100,
    name: 'bad_level_name',
    comment: '缺陷等级名称',
    nullable: true,
  })
  @ApiProperty()
  badLevelName: string;

  @Column({ type: 'float', nullable: true, name: 'bad_num', comment: '不良数' })
  @ApiProperty()
  badNum: number;

  @Column({ type: 'varchar', nullable: true, comment: '备注' })
  @ApiProperty()
  remark: string;

  @ManyToOne(() => WipBadRegistration, (badRegistration) => badRegistration.badRegistrationList, {
    onDelete: 'CASCADE', // 可根据需求选择删除策略
  })
  @JoinColumn({ name: 'bad_registration_code', referencedColumnName: 'badRegistrationCode' }) // 确保外键配置正确
  badRegistration: WipBadRegistration;
}
